import lombok.val;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class Demo29 {
    public static void main(String[] args) {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int sum = 0;
                for (int i = 1; i <= 10000; i++) {
                    sum++;
                }
                return sum;
            }
        };

        val futureTask = new FutureTask<Integer>(callable);
        var thread = new Thread(futureTask);
        thread.start();
        try {
            System.out.println(futureTask.get());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
